package servidorbancos.resources;

public class Distancia {
        public static double distanciaKM(double lat1, double lon1, double lat2, double lon2){
            double raioTerra = 6378;
            double lat1R = Math.toRadians(lat1);
            double lat2R = Math.toRadians(lat2);
            double lon1R = Math.toRadians(lon1);
            double lon2R = Math.toRadians(lon2);
            double firstBlock = Math.sin(lat1R) * Math.sin(lat2R);
            double secondBlock = Math.cos(lat1R) * Math.cos(lat2R) * Math.cos(lon2R-lon1R);
            return raioTerra *  ( Math.acos( firstBlock + secondBlock) );
        }
}
